home *** CD-ROM | disk | FTP | other *** search
- /* sindex.c - first occurence of a char in a string */
- #include "stdio.h"
-
- #define FAILURE -1 /* return value if string not found */
-
- int sindex(c,s) /* find char in string - return position */
- int c ; /* char to br found */
- char s[] ; /* string in which to look for c */
- {
- int i ;
-
- i = 0 ;
- while( s[i] != '\0' ) /* stop at end of the string */
- { if( c == s[i] )
- return( i ) ; /* c found - return its position */
- i = i + 1 ;
- }
- /* c was not found in s */
- return ( FAILURE ) ;
- }
-
-